package com.CMS.server;

import java.util.List;

import com.CMS.client.MenuService;
import com.CMS.server.dao.MenuDao;
import com.CMS.server.domain.Menu;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class RpcMenu extends RemoteServiceServlet implements MenuService{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7478951513141494720L;

	@Override
	public Menu getMenu() {
		try{
		MenuDao dao = new MenuDao();
		Menu m = dao.getAll().get(0);
		return m;
		}
		catch(Exception e){
			return null;
		}
	}

	@Override
	public void create(Menu m) {
		MenuDao dao = new MenuDao();
		dao.createEntity(m);
	}

	@Override
	public void updateMenu(Menu m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Menu> fetch() {
		MenuDao dao = new MenuDao();
		return dao.getAll();
	}

	@Override
	public void delete(long id) {
		MenuDao dao = new MenuDao();		
		dao.deleteEntity(dao.getEntity(id));
	}

	@Override
	public Menu update(long id, boolean flagDelete, String description) {
		Menu m = null;
		MenuDao dao = new MenuDao();
		m = dao.getEntity(id);
		m.setDescription(description);
		m.setFlagDelete(flagDelete);
		return dao.updateEntity(m);
	}

	@Override
	public void create(String description) {
		Menu m = new Menu();
		MenuDao dao = new MenuDao();
		m.setDescription(description);
		dao.createEntity(m);
	}

	@Override
	public Menu getMenu(long idMenu) {
		MenuDao dao = new MenuDao();
		return dao.getEntity(idMenu);
	}

}
